﻿using HK.Core.GUIEx.Protocol.Attribute;
using HK.Editor.GUIEx.Protocol.Drag;
using UnityEditor;
using UnityEngine;

namespace HK.Editor.GUIEx.Protocol
{
        
    /// <summary>
    /// 检索胶囊
    /// </summary>
    public struct SearchCapsule<TType>
    {
        public int Index;
        public TType Target;
    }
        
    /// <summary>
    /// 接口 : Drawer - GUI绘制器
    /// </summary>
    public interface IGUIDrawer
    {
        /// <summary>
        /// 是否从Unity调用绘制标志位
        /// </summary>
        bool DrawFromUnity { get; }
            
#region Options        

        /// <summary>
        /// 绘制背景
        /// </summary>
        bool DrawBg { get; }
            
        /// <summary>
        /// 只读
        /// </summary>
        bool ReadOnly { get; }
            
        /// <summary>
        /// 可展开
        /// </summary>
        bool Expandable { get; }
        
        /// <summary>
        /// 最小化
        /// </summary>
        bool Minimize { get; }
        
        /// <summary>
        /// 最大化
        /// </summary>
        bool Maximize { get; }
        
        /// <summary>
        /// 可追加
        /// </summary>
        bool Addable { get; }
		
        /// <summary>
        /// 可移除
        /// </summary>
        bool Removable { get; }
        
        /// <summary>
        /// 可枷锁
        /// </summary>
        bool Lockable { get; }
        
        /// <summary>
        /// 可拖拽
        /// </summary>
        bool Draggable { get; }
        
        /// <summary>
        /// 多行
        /// </summary>
        bool MultiLine { get; }
        
        /// <summary>
        /// 可检索
        /// </summary>
        bool Searchable { get; }
		
        /// <summary>
        /// 可点击
        /// </summary>
        bool Clickable { get; }
        
        /// <summary>
        /// 成员资产
        /// <para>* true : 成员为资产对象</para>
        /// </summary>
        bool MemberAsset { get; }
        
        /// <summary>
        /// 成员无标题
        /// </summary>
        bool MemberNoCaption { get; }
		
        /// <summary>
        /// 成员可拖拽
        /// </summary>
        bool MemberDraggable { get; }
        
        /// <summary>
        /// 成员唯一
        /// </summary>
        bool MemberDistinct { get; }
        
        /// <summary>
        /// 展开标志位
        /// </summary>
        bool IsExpanded { get; }
        
        /// <summary>
        /// 按Property绘制
        /// </summary>
        bool DrawProperty { get; }
        
#endregion

#region Caption

        /// <summary>
        /// 标题
        /// </summary>
        GUIContent Caption { get; }

#endregion

#region Size&Rect

        /// <summary>
        /// 总高度
        /// </summary>
        float TotalHeight { get; }

#endregion

        /// <summary>
        /// 背景色
        /// </summary>
        Color BgColor { get; }

#region SerializedProperty
        
        /// <summary>
        /// 自身Property
        /// </summary>
        SerializedProperty SelfProperty { get; }

#endregion

#region Drag

        /// <summary>
        /// 拖拽代理
        /// </summary>
        IDragAndDropSurrogate DragSurrogate { get; }

#endregion

    }

    /// <summary>
    /// 接口 : GUI绘制器 - 自定义
    /// </summary>
    public interface IGUIDiyDrawer : IGUIDrawer
    {
        
#region Size&Rect

        /// <summary>
        /// 取得高度
        /// <para>* 包含子节点及其展开/不展开的实际高度</para>
        /// </summary>
        /// <returns>高度</returns>
        float CalcTotalHeight();

#endregion

#region Draw

        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="iLevel">缩进层级</param>
        void Draw(int iLevel = 0);
        
        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="iRect">绘制矩形区域</param>
        /// <param name="iEvent">Event</param>
        /// <returns>绘制范围</returns>
        Rect Draw(Rect iRect, Event iEvent);

#endregion

    }
    
    /// <summary>
    /// 接口 : GUI绘制器
    /// </summary>
    /// <typeparam name="TAttribute">Property类型</typeparam>
    public interface IGUIPropertyDrawer<out TAttribute> : IGUIDrawer where TAttribute : PropertyAttribute, IGUIAttribute
    {
        /// <summary>
        /// 自身Property
        /// </summary>
        TAttribute SelfAttr { get; }
        
        /// <summary>
        /// 是否从Unity调用绘制标志位
        /// </summary>
        bool DrawFromUnity { get; }

#region SerializedProperty

        /// <summary>
        /// 可见子节点数
        /// <para>* 不包含自身</para>
        /// </summary>
        int VisibleChildCount { get; }

#endregion
        
#region Draw
        
        /// <summary>
        /// 绘制检索部
        /// </summary>
        /// <param name="iRect">绘制矩形区域</param>
        /// <param name="iProperty">Property</param>
        /// <param name="iCaption">标题</param>
        /// <returns>绘制范围</returns>
        void OnGUI(Rect iRect, SerializedProperty iProperty, GUIContent iCaption);

#endregion
        
    }
}
